#include <stdio.h>
#include <memory.h>

/* Convert a string such as AC or 10D to a number between 1 and 52. */
static int str_to_card(const char *s)
{
    int suit, rank;
    switch (s[0])
    {
    case 'A': rank = 1; break;
    case 'J': rank = 11; break;
    case 'Q': rank = 12; break;
    case 'K': rank = 13; break;
    case '1': rank = 10; s++; break; /* 10 */
    default:  rank = s[0] - '0'; break;
    }
    switch (s[1])
    {
    default:
    case 'C': suit = 0; break;
    case 'D': suit = 1; break;
    case 'H': suit = 2; break;
    case 'S': suit = 3; break;
    }
    return suit * 13 + rank;
}

template <class T, size_t AlphabetSize, size_t MaxSize>
class prefix_tree
{
    int nodes[MaxSize+1][AlphabetSize];
    int num_nodes;

public:
    prefix_tree() : num_nodes(0) 
    {
        memset(nodes[0], 0, sizeof(nodes[0]));
    }

    /* Clears the tree. */
    void clear()
    {
        num_nodes = 0;
        memset(nodes[0], 0, sizeof(nodes[0]));
    }

    /* Returns the number of nodes in the tree, excluding the root. */
    size_t size() const { return num_nodes; }

    /* Adds the string 's' of length 'len' into the prefix tree. Returns true
     * if a new node was created, or false if the string is fully contained in
     * the existing tree.
     */
    bool add_string(const T* s, size_t len)
    {
        size_t i, k = 0;

        /* Walk down the trie along the prefix of s. */
        for (i = 0; i < len; i++)
        {
            if (nodes[k][s[i]] == 0) /* not exists */
                break;
            k = nodes[k][s[i]];
        }
        if (i == len) /* the string is fully contained in the trie */
            return false;

        /* Add the remaining characters into to the tree. */
        memset(nodes[num_nodes+1], 0, sizeof(nodes[0])*(len - i));
        for (; i < len; i++)
        {
            k = nodes[k][s[i]] = ++num_nodes;
        }
        return true;
    }
};

static prefix_tree<int, 52, 100000> trie;

static int solve()
{
    int num_hands;
    if (!(scanf("%d", &num_hands) == 1 && num_hands > 0))
        return 0;

    trie.clear();
    for (int i = 0; i < num_hands; i++)
    {
        int cards[52], num_cards;
        scanf("%d", &num_cards);

        /* Read the hand and reverse the order of its cards. */
        for (int j = 0; j < num_cards; j++)
        {
            char s[5];
            scanf("%s", s);
            cards[num_cards - 1 - j] = str_to_card(s) - 1; /* 0 to 51 */
        }

        /* Add the string to the trie. */
        trie.add_string(cards, num_cards);
    }
    printf("%d\n", trie.size());
    return 1;
}

int main()
{
    while (solve());
    return 0;
}
